//
//  KKUploadDialog.m
//  DoMi
//
//  Created by 康凯 on 2016/11/27.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKUploadDialog.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@implementation KKUploadDialog

-(void)awakeFromNib{
    [super awakeFromNib];
    self.container.autoresizingMask =UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    self.container.translatesAutoresizingMaskIntoConstraints = YES;
    
    self.frame = [UIScreen mainScreen].bounds;
    self.container.frame=CGRectMake(0, screenHeight, screenWidth, 135);
    self.backgroundColor=[UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    
    UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(photoClick)];
    [self.photoView addGestureRecognizer:tap1];
    UITapGestureRecognizer *tap2=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pictureClick)];
    [self.pictureView addGestureRecognizer:tap2];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self dismiss];
}

#pragma mark 按钮--取消
- (IBAction)cancelBtn:(id)sender {
    [self dismiss];
}
#pragma mark 按钮--照相
-(void)photoClick{
    [self dismiss];
    self.uploadBlock(1);
}
#pragma mark 按钮--相册
-(void)pictureClick{
    [self dismiss];
    self.uploadBlock(2);
}

#pragma makr 弹框--展示
-(void)show{
    [appWindow addSubview:self];
    [UIView animateWithDuration:dialog_animation_time animations:^{
        self.container.transform = CGAffineTransformMakeTranslation(0,-135);
    }];
}
#pragma makr 弹框--消失
-(void)dismiss{
    [UIView animateWithDuration:dialog_animation_time animations:^{
        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
        self.container.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
